﻿package net.wangit.jdbc.sqltype;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;

import net.wangit.util.BytesUtil;


public class BinarySqlType extends NullableSqlType {

	private static final long serialVersionUID = 1L;

	public BinarySqlType() {
	}

	public String get(ResultSet rs, String name) throws SQLException {
		byte value[] = rs.getBytes(name);
		if (rs.wasNull())
			return null;
		else
			return Integer.toString(BytesUtil.toInt(value));
	}

	public void setNotNull(PreparedStatement st, String value, int index)
			throws SQLException {
		st.setBytes(index, BytesUtil.toBytes(Integer.parseInt(value)));
	}

	public int sqlType() {
		return Types.VARBINARY;
	}
}
